 package server;

 import database.DatabaseConnection;
 import handling.Auction.AuctionServer;
 import handling.cashshop.CashShopServer;
 import handling.channel.ChannelServer;
 import handling.chat.ChatServer;
 import handling.login.LoginServer;
 import handling.world.WorldAllianceService;
 import handling.world.WorldBroadcastService;
 import handling.world.WorldFamilyService;
 import handling.world.WorldGuildService;
 import java.lang.management.ManagementFactory;
 import java.sql.SQLException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import tools.MaplePacketCreator;
 import tools.packet.UIPacket;


 public class ShutdownServer
   implements ShutdownServerMBean
 {
/*  26 */   private static final Logger log = LogManager.getLogger(ShutdownServer.class);
   public static ShutdownServer instance;
   public static boolean running = false;
/*  29 */   private int time = 0;
   private boolean first = true;

   public static void registerMBean() {
/*  33 */     MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
     try {
/*  35 */       instance = new ShutdownServer();
/*  36 */       mBeanServer.registerMBean(instance, new ObjectName("server:type=ShutdownServer"));
/*  37 */     } catch (Exception e) {
/*  38 */       log.error("Error registering Shutdown MBean", e);
     }
   }

   public static ShutdownServer getInstance() {
/*  43 */     return instance;
   }

   public int getTime() {
/*  47 */     return this.time;
   }

   public void setTime(int time) {
/*  51 */     this.time = time;
   }


   public void shutdown() {
/*  56 */     run();
   }


   public void run() {
/*  61 */     synchronized (this) {
/*  62 */       if (running) {
         return;
       }
/*  65 */       running = true;
     }

/*  68 */     if (this.time != 0) {
/*  69 */       WorldBroadcastService.getInstance().broadcastMessage(MaplePacketCreator.serverNotice(0, " 游戏服务器将在" + getTime() + "分钟后关闭维护，请玩家安全下线..."));
/*  70 */       WorldBroadcastService.getInstance().broadcastMessage(UIPacket.clearMidMsg());
/*  71 */       WorldBroadcastService.getInstance().broadcastMessage(UIPacket.getMidMsg("游戏将于 " + getTime() + " 分钟之后关闭维护.请玩家安全下线.", true, 0));
/*  72 */       if (this.first) {
/*  73 */         this.first = false;
/*  74 */         for (ChannelServer cs : ChannelServer.getAllInstances()) {
/*  75 */           cs.setShutdown();
/*  76 */           cs.setServerMessage("游戏服务器将关闭维护，请玩家安全下线...");
/*  77 */           cs.closeAllMerchants();
/*  78 */           cs.closeAllFisher();
         }
       }
/*  81 */       running = false;
       return;
     }
/*  84 */     WorldGuildService.getInstance().save();
/*  85 */     WorldAllianceService.getInstance().save();
/*  86 */     WorldFamilyService.getInstance().save();
/*  87 */     Integer[] chs = (Integer[])ChannelServer.getAllInstance().toArray((Object[])new Integer[0]); Integer[] arrayOfInteger1; int i; byte b;
/*  88 */     for (arrayOfInteger1 = chs, i = arrayOfInteger1.length, b = 0; b < i; ) { int j = arrayOfInteger1[b].intValue();
       try {
/*  90 */         ChannelServer cs = ChannelServer.getInstance(j);
/*  91 */         synchronized (this) {
/*  92 */           cs.shutdown();
         }
/*  94 */       } catch (Exception e) {
/*  95 */         log.error("关闭服务端错误" + e);
       }  b++; }

/*  98 */     LoginServer.shutdown();
/*  99 */     CashShopServer.shutdown();
/* 100 */     AuctionServer.shutdown();
/* 101 */     ChatServer.shutdown();
/* 102 */     System.out.println("正在关闭时钟线程...");
/* 103 */     Timer.WorldTimer.getInstance().stop();
/* 104 */     Timer.MapTimer.getInstance().stop();
/* 105 */     Timer.BuffTimer.getInstance().stop();
/* 106 */     Timer.CloneTimer.getInstance().stop();
/* 107 */     Timer.EventTimer.getInstance().stop();
/* 108 */     Timer.EtcTimer.getInstance().stop();
/* 109 */     Timer.PingTimer.getInstance().stop();
/* 110 */     System.out.println("正在关闭数据库连接...");
     try {
/* 112 */       DatabaseConnection.closeAll();
/* 113 */     } catch (SQLException e) {
/* 114 */       log.error("关闭数据库连接错误" + e);
     }
/* 116 */     System.out.println("服务端关闭完成...");
   }
 }


/* Location:              C:\PGX\Server.jar!\server\ShutdownServer.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */